package cn.ruituo.adv8.client;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client1 {
    public static void main(String[] args) {
        //localhost
        //读到一行，表示结束，再回复
        try {
            Socket s=new Socket("192.168.1.132",8880);
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            BufferedReader br=new BufferedReader(new InputStreamReader(in));
            PrintWriter pw=new PrintWriter(out,true);
            Scanner sc=new Scanner(System.in);
            while (true){
                System.out.println("想对服务器说啥：");
                String q=sc.next();
                pw.println(q);
                String reply=br.readLine();
                System.out.println("服务器说："+reply);
                if(q.equals("exit"))
                    break;
            }
            //聊天
            s.close();//最好再final中
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
